package com.suray.basic.wcs.utils.typedef;

public class BaseDataType {

    /**
     * 数据
     */
    protected int param;

    /**
     * 长度（位）
     */
    protected int size;

    /**
     * 数据名称
     */
    private String name;

    /**
     * 数据描述
     */
    private String des;

    private int offset;

    public BaseDataType(int size, String name, String des) {
        if (size <= 0) {
            throw new RuntimeException("数据长度错误：" + size + ", 长度必须 > 0");
        }

        this.size = size;
        this.name = name;
        this.des = des;

        offset = 1;

        for (int i = 1; i < size; i++) {
            offset = (offset << 1) + 1;
        }
    }

    public String getName() {
        return name;
    }

    public String getDes() {
        return des;
    }

    public int getSize() {
        return size;
    }

    public int getParam() {
        return param & offset;
    }

    public void setParam(int param) {
        this.param = param & offset;
    }

    @Override
    public String toString() {
        return "name:" + name
                + ", description:" + des
                + ", value:" + param;
    }
}
